var MAX_PERCENT = 100;
var currTarget = null;
var editIndex = undefined;
var currPercArr=[];
$(function(){
    doSearch();
    $(document).on('blur', '.datagrid-view td[field=currRate] input', function(){
        $('#tt').edatagrid('saveRow');
    });
});    
function doSearch(){
	$("#container").css({'display':'block'});
    var timeData=[];
    var getArray=[];
    var getArray2=[];
    var  markVal=$('#mark').val();
    retentHandler.getTimeX();
    var data= $('#tt').datagrid('getRows');
    if(data.length!=0){
        $("#container").css({'width':'100%','height':'600px','margin':'0 auto'});
    }else{
        $("#container").css({'display':'none'});
    }
    $.each(data,function(index,mod){
        getArray.push(mod.totalRate);
        currPercArr.push(mod.currRate);
    });
    retentHandler.showHighChart(currPercArr);
}
function add(){
    showMyWindow('模拟配置管理 |模拟新增配置管理', '/channelapk/addConfig', 800, 500);
}
function edit(){
	var row = $('#tt').datagrid('getSelected');
	var mark = row.mark;
    if (row){
	    showMyWindow('模拟器配置管理 | 编辑模拟器配置', '/channelapk/'+mark+'/configUpdate', 700, 500);
    } else {
    	showMsg(market.content.title, market.content.tips, alert);
    }
}
function saveRow(){
    var rows = $('#tt').datagrid('getRows');
    if((rows[95].totalRate < 100 || rows[95].totalRate > 100)) {
        $.messager.alert('提示:','请确保总的占比为100%！');
        return;
    }
    showConfirm(market.content.title, "确定要保存么", function(){
        $.ajax({
            url: '/timemodel/batchUpdate',
            type: 'POST',
            data: JSON.stringify(rows),
            dataType: 'json',
            contentType: "application/json",
            success: function(data){
                $.messager.alert('提示:','保存成功！');;
            },
            error:function(data){   
                 $.messager.alert('提示:','保存失败！');;
                 console.log(data);
            }
        });
    });
}

function formatterModel(value,row,index){
	 var a = '<a href="#" onclick="editModel('+"'"+row.mark+"'"+')">配置</a> ';
	 return a;
}


function formatterValue(value,row,index){
	 return value.toFixed(2);;
}



//占比输入框限制，最大为100且只最多能有两位小数点 

$(document).on("keyup afterpaste","td[field='timePercent'] input",function(e){
		 this.value = this.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符   
		 this.value = this.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的   
		 this.value = this.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");  
		 this.value = this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数   
		 if(this.value.indexOf(".")< 0 && this.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额  
			 this.value= parseFloat(this.value);  
		 }  
		 if(this.value>100){
			 this.value = 100;
		 }
})
//日限输入框限制为数字
$(document).on("keyup afterpaste","td[field='spDayLimit'] input",function(){
	$("td[field='spDayLimit'] input").attr("maxlength",'9');
	this.value=this.value.replace(/\D/g,'');
})
